package com.conduit.autoit;

import java.io.BufferedWriter;
import java.io.FileWriter;

import com.conduit.enums.AutoItCommands;
import com.conduit.utils.Command;
import com.conduit.utils.Execute;

public class AutoItAgent {

	Command command;
	static String stdOut;

	public static String getStdOut() {
		return stdOut;
	}

	public static void setStdOut(String stdOut) {
		AutoItAgent.stdOut = stdOut;
	}

	public static void runCommand(AutoItCommands command, String... args) {
		try {
			FileWriter fstream = new FileWriter("c:\\out.au3");
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(String.format(command.getCommand(), args));
			out.close();
			Command cmd = new Command();
			//cmd.setCmd("c:\\Program Files\\AutoIt3\\AutoIt3.exe c:\\out.au3".split(" "));
			cmd.setCmd("c:\\Program Files\\AutoIt3\\AutoIt3.exe c:\\out.au3".split(" "));
			Execute.execute(cmd, true,false,true);
			stdOut = cmd.getStdout().toString();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}
}
